/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedBean.TX.CustomerIOTRPortal;

import Helper.Helper_OutletReservation;
import session.TX.CustomerReservationSBRemote;
import entity.OutletReservation;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

/**
 *
 * @author Lu Xiaodi
 */
@ManagedBean(name = "customerReservationManagedBean")
@ViewScoped
public class CustomerReservationMB implements Serializable {

    @EJB
    CustomerReservationSBRemote reservationBean;
    private String customerEmail;
    private String dateStr;
    private Date selectedDate;
    private OutletReservation selectedReservation;

    public CustomerReservationMB() {
        //outletName = "McdonaldNUS";
    }

    public List<OutletReservation> getReservationByCus() {
        return reservationBean.getAllCustomerReservationList(getCustomerEmail());
    }

    public void cancelMessage(OutletReservation or) {
        Long rId = or.getId();
        System.out.println(rId);
        if (!(rId == null)) {
            Boolean cancelled = reservationBean.cancelReservation(rId);
            System.out.println("dELETE end 1");
            if (cancelled) {
                System.out.println("dELETE end 2");
                //  message = "Reservation ID :" + rId + " has been cancelled successfully";
            } else {
                System.out.println("dELETE end 0");
                //  message = "Reservation ID is invalid";
            }

        } else {
            System.out.println("dELETE end ttt");
            // message = "";
        }


    }

    public String getDateStr() {
        return dateStr;
    }

    public void setDateStr(String dateStr) {
        this.dateStr = dateStr;
    }

    public Long getOutletId() {
        return (Long) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("outletId");
    }

    public String getCustomerEmail() {
        return FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("email").toString();
    }

    public Date getSelectedDate() {
        return selectedDate;
    }

    public void setSelectedDate(Date selectedDate) {
        this.selectedDate = selectedDate;
    }

    /**
     * @return the selectedReservation
     */
    public OutletReservation getSelectedReservation() {
        return selectedReservation;
    }

    /**
     * @param selectedReservation the selectedReservation to set
     */
    public void setSelectedReservation(OutletReservation selectedReservation) {
        this.selectedReservation = selectedReservation;
    }
}